<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocketClientDemo</title>
    <script  type="text/javascript">
        var socket
        if (window.WebSocket){
            socket =  new WebSocket("ws://192.168.2.252:8093/bbx")
            socket.onopen = function (ev) {
                var el = document.getElementById("resMessage");
                el.value = el.value+"建立连接"
            }
            socket.onmessage = function (ev) {
                var el = document.getElementById("resMessage");
                el.value = el.value+"\n"+ev.data
            }
            socket.onclose = function (ev) {
                var el = document.getElementById("resMessage");
                el.value = el.value+"\n"+"关闭连接"
            }
        } else {
            alert("浏览器不支持WebSocket");
        }

    function sub() {
            console.log("点击提交")
        if (!window.WebSocket) {
            alert("浏览器不支持WebSocket")
        }
        if (socket.readyState == WebSocket.OPEN) {
            var el = document.getElementById("inputMessage");
            socket.send(el.value)
            el.value = ""
        }
    }


    </script>
</head>
<body>

<form>
    <textarea id="inputMessage" style="width: 350px;height: 200px"></textarea>
    <input type="button" value="提交" onclick="sub()"><br><br>
    <textarea id="resMessage" style="width: 350px;height: 200px"></textarea>

</form>


</body>
</html>